package ink.lovejinhu.leetcode;

import java.util.HashSet;

/**
 * @author jinhu
 * created 2021-07-13 14:30
 */
public class Solution_0349 {
    /**
     * 两个数组的交集
     *
     * @param nums1
     * @param nums2
     * @return
     */
    public int[] intersection(int[] nums1, int[] nums2) {

        HashSet<Integer> map = new HashSet<>();
        HashSet<Integer> resSet = new HashSet<Integer>();
        for (int i = 0; i < nums1.length; i++) {
            map.add(nums1[i]);
        }
        for (int i = 0; i < nums2.length; i++) {
            if (map.contains(nums2[i])) {
                resSet.add(nums2[i]);
            }
        }
        int[] resArray = new int[resSet.size()];
        int i = 0;
        for (int v0 : resSet
        ) {
            resArray[i] = v0;
            i++;

        }

        return resArray;

    }

}
